<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022\3\28 0028
 * Time: 16:55
 */
$oldTotal=7;
$total = 5.8; //待划分的数字


$diff = $oldTotal - $total;

$diff= $diff/4;


$first = 3 / 16;
$second = 3 / 16;
$three = 3 / 16;
$four = 7 / 16;

$randNum=randFloat(0,$diff);

$firstNum = $total * $first +$randNum;

$randNum=randFloat(0,$diff);
$secondNum = $total * $second+$randNum;;

$randNum=randFloat(0,$diff);
$threeNum = $total * $three+$randNum;;

$randNum=randFloat(0,$diff);
$foureNum = $total * $four+$randNum;;


echo $firstNum ;
echo "</br>";

echo $secondNum;

echo "</br>";
echo $threeNum;

echo "</br>";

echo $foureNum;


 function randFloat($min = 0, $max = 1)
{
    return round($min + mt_rand() / mt_getrandmax() * ($max - $min),2);
}
